package com.dpj.park_test;

import java.util.concurrent.locks.LockSupport;

public class AlternatePrint2 {
    static Thread t1;
    static  Thread t2;
    static  Thread t3;
    public static void main(String[] args) {
        ParkUnPark pu=new ParkUnPark(5);
        t1=new Thread(()->{
            pu.print("a",t2);
        });

        t2=new Thread(()->{
            pu.print("b",t3);
        });

        t3=new Thread(()->{
            pu.print("c",t1);
        });

        t1.start();
        t2.start();
        t3.start();
        LockSupport.unpark(t1);
    }
}
class ParkUnPark{

    public void  print(String str,Thread next){
        for (int i = 0; i < loopNumber; i++) {
            LockSupport.park();
            System.out.println(str);
            LockSupport.unpark(next);
        }

    }

    private int loopNumber;
    public ParkUnPark(int loopNumber){
        this.loopNumber=loopNumber;
    }
}
